document.querySelector('.header i').addEventListener('click', async function () {
     history.back()
})
const ipt = document.querySelector('.search_ipt')
let arr = JSON.parse(localStorage.getItem('pinglun')) || []
const box = document.querySelector('.box')
const boxContent = document.querySelector('.box_content')
const btn =document.querySelector('.search_btn')
render()
function render () {
  console.log(arr);
  if (arr.length === 0) {
    box.style.display = 'none'
  } else {
    box.style.display='block'
  }
   let newArr = arr.map((item ,index) => {
     return ` <div class="txt" data.id=${index}>${item.name}</div>`
  })
  boxContent.innerHTML=newArr.join('')
}
boxContent.addEventListener('click',function (e) {
  if (e.target.tagName === 'DIV') { 
    console.log(e.target)
    ipt.value = e.target.innerHTML
    btn.click()
  }
})
//点击添加搜索记录
btn.addEventListener('click',async function () {
  if (ipt.value.trim()=='')return
  arr.push({ name: ipt.value })
  localStorage.setItem('pinglun', JSON.stringify(arr))
  location.href=`./list.html?goodsId=${ipt.value}`
  render()
  ipt.value=''
})

//删除记录
document.querySelector('.box_img').addEventListener('click',function () {
  localStorage.clear('pinglun')
  arr=[]
  render()
})



